-
Notifications
You must be signed in to change notification settings - Fork 589
S_invlist_trim - don't SvPV_renew if SvLEN(invlist) is < PTRSIZE larger #23111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blead
Are you sure you want to change the base?
Conversation
Tow comments:
|
S_invlist_trim_pv_shrink_evt_trace.txt There are so many problems with this API, IDK where to start. For example, the same Also "new 0x9" which is Suggestion, why not just turn off ln 50
ln 195
ln 51
ln 1425
Here is a sample of the different kinds of actual sizes/SvLEN values encountered by this API during a
|
I'm just gonna drop a link here in this randomly picked ticket #23359 There are around 6 - 10 stalled PRs open related to the regexp engine's abuse of RenewTrim() and And another about 8-12 bug reports without code/patches/fixes open right now related to the regexp engine's abuse of RenewTrim() and And 2-6 bug reports without code/patches/fixes open right now related to the |
bd9b4e9
to
80dd43e
Compare
I've modified this PR to make use of the recently introduced The current code does still see Ready for review. |
Though if there's consensus that the remaining amount of reallocation for small gain is undesirable, I'm not opposed to re-tweaking the condition from:
to something like:
|
regcomp_invlist.c
Outdated
* the malloc implementation in use. */ | ||
|
||
const STRLEN min_size = (PERL_STRLEN_NEW_MIN > TO_INTERNAL_SIZE(1) + 1) | ||
? PERL_STRLEN_NEW_MIN : TO_INTERNAL_SIZE(1) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use MAX() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, thanks. I'll do that.
How many bytes do we consider too little to bother with trimming? I don't know. But I'd like to see some ideas. I'd be fine if others are willing to tolerate some excess that doesn't get trimmed in the service of fewer malloc calls |
I don't have a good understanding of the lifetime of invlists. Do some hang around under interpreter destruction but others might be short lived? (Less shrinkage seems like a reasonable trade off for the latter, but less so for the former.) |
Currently, `S_invlist_trim` always calls `SvPV_renew(invlist, <size>)`, which is a macro wrapping a call to `safesysrealloc()`. However, `SvLEN(invlist)` is often already exactly the desired size, or it is larger by less than the size of a pointer. With this commit, the new `expected_size` macro is used to reduce the number of cases in which S_invlist_trim will try to shrink a buffer but no shrinkage is likely to occur. (For example, if the desired size is less than the minimum actual allocation size.)
80dd43e
to
573e4fd
Compare
Currently,
S_invlist_trim
always callsSvPV_renew(invlist, <size>)
,which is a macro wrapping a call to
safesysrealloc()
.However,
SvLEN(invlist)
is often already exactly the desired size,or it is larger by less than the size of a pointer. With this commit,
such cases just return without calling
SvPV_renew()
.